﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeekWork929.infrastrunceture
{
    public class BaseRepository<T> :IBaseIRepository<T> where T : class
    {
        private readonly MyDbContext db;
        public BaseRepository(MyDbContext db)
        {
            this.db = db;
        }

        public async Task<int> Add(T entity)
        {
            await db.Set<T>().AddAsync(entity);
            return await db.SaveChangesAsync(); 
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public Task<int> Update(T entity)
        {
           db.Set<T>().Update(entity);
           return db.SaveChangesAsync();
        }
    }
}
